package com.easepal7506a.project.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.easepal7506a.project.Constant.CommmandNum;
import com.easepal7506a.project.R;
import com.easepal7506a.project.network.CommondManager;
import com.example.reslib.utils.ToastUtils;
import com.ogawa.base.callback.NormalCallback;
import com.ogawa.base.network.BaseResponse;
import com.ogawa.base.utils.CommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by FHB on 2018/4/24.
 */
public class LayoutGears6_7506 extends RelativeLayout implements View.OnClickListener {
    private List<ImageView> mIvLists = new ArrayList<>();
    private int mType;
    private ImageView mIvSub ;
    private ImageView mIvAdd;
    private Context mContext;
    public LayoutGears6_7506(Context context) {
        super(context);
        mContext = context;
    }

    public LayoutGears6_7506(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mIvLists.clear();
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_0));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_1));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_2));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_3));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_4));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_5));
        mIvLists.add((ImageView) findViewById(R.id.iv_gears6_6));
        mIvSub = findViewById(R.id.iv_gears6_sub);
        mIvAdd =  findViewById(R.id.iv_gears6_add);
        mIvSub.setOnClickListener(this);
        mIvAdd.setOnClickListener(this);
    }
    public  void setShow(int position){
        for(int i =0;i<mIvLists.size();i++){
            if(i==position){
                mIvLists.get(i).setVisibility(VISIBLE);
            }
            else {
                mIvLists.get(i).setVisibility(GONE);
            }
        }
    }


    /**
     *
     * @param type 1：3D调节
     */
    public void setType(int type){
        mType = type;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.iv_gears6_sub) {
            if (CommonUtil.isFastClick()) {
                return;
            } else {
                if(mType==1){
                    //执行3D调节减
                    sendCommond(CommmandNum.JIX3DSUB);
                }

            }

        }
        else if (i == R.id.iv_gears6_add) {
            if (CommonUtil.isFastClick()) {
                return;
            } else {
                if(mType==1){
                    //执行3D调节加
                    sendCommond(CommmandNum.JIX3DADD);

                }



            }




        }
    }
    private void sendCommond(String code){
        CommondManager.getInst().sendShortCommond(code, new NormalCallback() {
            @Override
            public void onSuccess(BaseResponse<String> program) {

            }

            @Override
            public void onFailure(String error) {
                ToastUtils.showLongToast(mContext,error+"");
            }
        });
    }
}
